home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Applications / ARTAbrot 1.0 / Main_ARTAbrot.c < prev    next >
C/C++ Source or Header  |  1993-08-23  |  23KB  |  626 lines

  1. /* Main_ARTAbrot */
  2.  
  3. /* Program name:  Main_ARTAbrot   
  4.  Function:  This is the main module for this program.  
  5. History: 8/18/93 Original by George Warner
  6.    */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #include "ComUtil_ARTAbrot.h"    /* Common */
  12.  
  13. #include "AB_Alert.h"    /* Alert */
  14. #include "About_ARTAbrot.h"    /* Modeless Dialog */
  15. #include "Enter_Coordinates.h"    /* Modeless Dialog */
  16. #include "ARTAbrot.h"    /* Window */
  17. #include "Menu_ARTAbrot.h"    /* Menus */
  18.  
  19. Boolean        DoIt;                                /* Flag saying an event is ready */
  20. short        code;                                    /* Determine event type */
  21. WindowPtr    whichWindow;                            /* See which window for event */
  22. long        mResult;                                /* Menu list and item selected values */
  23. short        theMenu,theItem;                        /* Menu list and item selected */
  24. Boolean        Is_A_Dialog;                        /* Flag for modless dialogs */
  25. short        charCode, itemHit;                    /* For modeless dialogs*/
  26. char        ch;                                    /* Key pressed in Ascii */
  27. Boolean        DoTheModelessEvent, CmdDown;        /* For modeless dialogs*/
  28. WindowPeek    thePeeked;                            /* For modeless dialogs*/
  29.  
  30. /* Handle key strokes */
  31. static void DoKeyEvent(void);
  32.  
  33. /* Handle a diskette inserted */
  34. static void DoDiskEvent(void);
  35.  
  36. /* Handle a window being resized */
  37. static void DoGrow(WindowPtr whichWindow);
  38.  
  39. /* Handle a window being dragged */
  40. static void DoDrag(WindowPtr whichWindow);
  41.  
  42. /* Handle a window goaway box */
  43. static void DoGoAway(WindowPtr whichWindow);
  44.  
  45. /* Handle an update to the window */
  46. static void DoUpdate(void);
  47.  
  48.  
  49. /* MAIN entry point */
  50. void main(void);
  51.  
  52. /* Handle the OS event */
  53. void DoOSEvent(EventRecord *myEvent);
  54.  
  55.  
  56. /* Routine: DoOSEvent */
  57. /* Purpose: Handle DoOSEvents */
  58.  
  59. void DoOSEvent(EventRecord *myEvent)
  60. {
  61.  
  62. if (((myEvent->message & osEvtMessageMask) >> 24) == suspendResumeMessage)/*  See which  */
  63.     {
  64.     if ((myEvent->message & resumeFlag) == 0)        /* Suspend */
  65.         {
  66.         InTheForeground = FALSE;
  67.         }
  68.     else
  69.         {
  70.         InTheForeground = TRUE;
  71.         }                                        /* End of IF */
  72.     }                                            /* End of IF */
  73. }
  74.  
  75. /* ======================================================= */
  76.  
  77. /* ======================================================= */
  78.  
  79. /* Routine: WNEIsImplemented */
  80. /* Purpose: See if the MultiFinder trap, WaitNextEvent, is available */
  81.  
  82. Boolean IsWNEIsImplemented()                /* See if WaitNextEvent is available */
  83. {
  84. #define    WNETrapNumber    0xA860                /* The expected trap number */
  85. #define    kGestaltTrapID    0xA1AD                /* The expected trap number */
  86.  
  87. SysEnvRec    theWorld;                        /* Environment record */
  88. OSErr    discardError;                        /* Error code returned */
  89. Boolean    theWNEIsImplemented;                /* Value to return */
  90. long    result;                                /* Value returned */
  91.  
  92.     Black_ForeColor.red = 0x0000;  Black_ForeColor.green = 0x0000;    Black_ForeColor.blue = 0x0000;  /* Get black color */
  93.     White_BackColor.red = 0xFFFF;  White_BackColor.green = 0xFFFF;  White_BackColor.blue = 0xFFFF;  /* Get white color */
  94.  
  95.     HasColorQD = FALSE;                        /* Init to no color QuickDraw */
  96.     HasFPU = FALSE;                            /* Init to no floating point chip */
  97.     HasAppleEvents = FALSE;                    /* Whether AppleEvents are available */
  98.     HasAliasMgr = FALSE;                    /* Whether AliasMgr is available */
  99.     HasEditionMgr = FALSE;                    /* Whether EditionMgr is available */
  100.     HasGestalt = FALSE;                        /* Whether Gestalt is available */
  101.     HasNewStdFile = FALSE;                    /* Whether HasNewStdFile is available */
  102.     HasPPCToolbox = FALSE;                    /* Whether PPCToolbox is available */
  103.     Has32BitQuickDraw = FALSE;                /* Whether 32Bit QuickDraw is available */
  104.     InTheForeground = TRUE;                    /* Init to a foreground app */
  105.     discardError = SysEnvirons(1, &theWorld);    /* Check how old this system is */
  106.     if (theWorld.machineType < 0) {            /* Negative means really old */
  107.         theWNEIsImplemented = FALSE;        /* Really old ROMs, no WNE possible */
  108.     }
  109.     else {
  110.         theWNEIsImplemented = CheckTrapAvailable(WNETrapNumber, ToolTrap);/* See if trap is there */
  111.         HasColorQD = theWorld.hasColorQD;    /* Flag for Color QuickDraw being available */
  112.         HasFPU = theWorld.hasFPU;            /* Flag for Floating Point Math Chip being available */
  113.         HasGestalt = CheckTrapAvailable(kGestaltTrapID, ToolTrap);    /* Whether Gestalt is available */
  114.         if (HasGestalt) {                    /* Do if Gestalt is available */
  115.             discardError = Gestalt(gestaltAliasMgrAttr,&result);
  116.             if ((discardError == 0) && ((result & (0x00000001 << gestaltAliasMgrPresent)) != 0))
  117.                 HasAliasMgr = TRUE;
  118.  
  119.             discardError = Gestalt(gestaltEditionMgrAttr,&result);
  120.             if ((discardError == 0) && ((result & (0x00000001 << gestaltEditionMgrPresent)) != 0))
  121.                 HasEditionMgr = TRUE;
  122.  
  123.             discardError = Gestalt(gestaltAppleEventsAttr,&result);
  124.             if ((discardError == 0) && ((result & (0x00000001 << gestaltAppleEventsPresent)) != 0))
  125.                 HasAppleEvents = TRUE;
  126.  
  127.             discardError = Gestalt(gestaltPPCToolboxAttr,&result);
  128.             if ((discardError == 0) && ((result & (0x00000001 << gestaltPPCToolboxPresent)) != 0))
  129.                 HasPPCToolbox = TRUE;
  130.  
  131.             discardError = Gestalt(gestaltQuickdrawVersion,&result);
  132.             if ((discardError == 0) && ((result & gestalt32BitQD) != 0))
  133.                 Has32BitQuickDraw = TRUE;
  134.  
  135.             discardError = Gestalt(gestaltStandardFileAttr,&result);
  136.             if ((discardError == 0) && ((result & (0x00000001 << gestaltStandardFile58)) != 0))
  137.                 HasNewStdFile = TRUE;
  138.         }
  139.     }
  140.     return(theWNEIsImplemented);
  141. }
  142.  
  143. /* ======================================================= */
  144.  
  145. /* Routine: Handle_User_Event */
  146. /* Purpose: Check for user events */
  147.  
  148. void Handle_User_Event()                            /* Check for user events */
  149. {
  150. UserEventRec    TheUserEvent;                        /* The user event */
  151.  
  152. GetUserEvent(&TheUserEvent);                        /* Check for any user events */
  153. if (TheUserEvent.ID != UserEvent_None)                /* Only do if we have any */
  154.     {
  155.  
  156.     switch (TheUserEvent.ID)                        /* Key off the Event ID */
  157.         {
  158.         case UserEvent_Open_Window:             /* Open a Window or Modeless dialog */
  159.             switch (TheUserEvent.ID2)                /* Do the appropiate window */
  160.                 {
  161.                 case Res_W_ARTAbrot: 
  162.                     Open_ARTAbrot();        /* Open this window */
  163.                     break;
  164.                 case Res_MD_About_ARTAbrot:
  165.                     Open_About_ARTAbrot();/* Open this modeless dialog */
  166.                     break;
  167.                 case Res_MD_Enter_Coordinat:
  168.                     Open_Enter_Coordinat();/* Open this modeless dialog */
  169.                     break;
  170.                 default:                        /* Handle others */
  171.                     break;
  172.                 }                                /* End of the switch */
  173.             break;
  174.  
  175.         case UserEvent_Close_Window:             /* Close a Window or Modeless dialog */
  176.             switch (TheUserEvent.ID2) {            /* Do the appropiate window */
  177.                 case Res_W_ARTAbrot:
  178.                     Close_ARTAbrot(WPtr_ARTAbrot);/* Close this window */
  179.                     break;
  180.                 case Res_MD_About_ARTAbrot:
  181.                     Close_About_ARTAbrot(WPtr_About_ARTAbrot);/* Close this modeless dialog */
  182.                     break;
  183.                 case Res_MD_Enter_Coordinat:
  184.                     Close_Enter_Coordinat(WPtr_Enter_Coordinat);/* Close this modeless dialog */
  185.                     break;
  186.                 default:                        /* Handle others */
  187.                     break;
  188.                 }                                /* End of the switch */
  189.  
  190.             break;
  191.         default:                                /* Not standard, must be program specific */
  192.             break;
  193.         }                                        /* End of switch */
  194.     }                                            /* End of IF */
  195. }
  196.  
  197. /* ======================================================= */
  198.  
  199. /* Routine: DoKeyEvent */
  200. /* Purpose: Handle a key pressed */
  201.  
  202. static void DoKeyEvent()                            /* Handle key presses */
  203. {
  204. short    charCode;                                    /* Key code */
  205. char    ch;                                        /* Key pressed in Ascii */
  206. long    mResult;                                    /* Menu list and item, if a command key */
  207. short    theMenu,theItem;                            /* Menu list and item, if command key */
  208.  
  209. charCode = myEvent.message & charCodeMask;            /* Get the character */
  210. ch = (char)charCode;                                /* Change it to ASCII */
  211.  
  212. if ((myEvent.modifiers & cmdKey) != 0)                /* See if Command key is down */
  213.     {
  214.     mResult = MenuKey(ch);                            /* See if a menu selection */
  215.     theMenu = HiWord(mResult);                        /* Get the menu list number */
  216.     theItem = LoWord(mResult);                        /* Get the menu item number */
  217.     if (theMenu != 0)                                /* See if a list was selected */
  218.         Handle_My_Menu(theMenu, theItem);        /* Do the menu selection */
  219.  
  220.     if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))/* See if a standard Cut */
  221.         TECut(theInput);                        /* Handle a Cut in a TE area */
  222.     if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))/* See if a standard Copy */
  223.         TECopy(theInput);                        /* Handle a Copy in a TE area */
  224.     if (((ch == 'v')  ||  (ch == 'V')) && (theInput != NIL))/* See if a standard Paste */
  225.         TEPaste(theInput);                        /* Handle a Paste in a TE area */
  226.     }                                            /* End of IF */
  227. else if (theInput != NIL)
  228.     TEKey(ch,theInput);                        /* Place the normal key stroke */
  229.  
  230. }
  231.  
  232. /* ======================================================= */
  233.  
  234. /* Routine: DoDiskEvent */
  235. /* Purpose: Handle a diskette inserted */
  236.  
  237. static void DoDiskEvent()                            /* Handle disk inserted */
  238. {
  239. short    theError;                                    /* Error returned from mount */
  240.  
  241. if (HiWord(myEvent.message) != noErr)                /* See if a diskette mount error */
  242.     {
  243.     myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) / 2) - (304 / 2);/* Center horz */
  244.     myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) - (104 / 2);/* Top 3ed vertically */
  245.     InitCursor();                                    /* Make sure it has an arrow cursor */
  246.     theError = DIBadMount(myEvent.where, myEvent.message);/* Let the OS handle the diskette */
  247.     }                                            /* End of IF */
  248.  
  249. }
  250.  
  251. /* ======================================================= */
  252.  
  253. /* Routine: DoGrow */
  254. /* Purpose: Handle a window resize */
  255.  
  256. static void DoGrow(WindowPtr whichWindow)
  257. {
  258. Rect    OldRect;                                    /* Window rect before the grow */
  259. Point    myPt;                                        /* Point for tracking grow box */
  260. Rect    GrowRect;                                    /* Set the grow bounds */
  261. long    mResult;                                    /* Result from the grow */
  262.  
  263. if (!Doing_MovableModal)                            /* Select proper window */
  264.     {
  265.     if (whichWindow != nil)                        /* See if we have a legal window */
  266.         {
  267.         SetPort(whichWindow);                        /* Get ready to draw in this window */
  268.  
  269.         myPt = myEvent.where;                        /* Get mouse position */
  270.         GlobalToLocal(&myPt);                        /* Make it relative */
  271.  
  272.         OldRect = whichWindow->portRect;            /* Save the rect before resizing */
  273.  
  274.         SetRect(&GrowRect, 4, 4, (qd.screenBits.bounds.right - qd.screenBits.bounds.left)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  275.         mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
  276.         SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
  277.  
  278.  
  279.         SetPort(whichWindow);                        /* Get ready to draw in this window */
  280.  
  281.         myPt.h = whichWindow->portRect.right - whichWindow->portRect.left;/* Local right edge */
  282.         myPt.v = whichWindow->portRect.bottom - whichWindow->portRect.top;/* Local bottom edge */
  283.  
  284.         SetRect(&GrowRect, 0, OldRect.bottom - 15, OldRect.right + 15, OldRect.bottom + 15);/* Position for horz scrollbar area */
  285.         EraseRect(&GrowRect);                        /* Erase old area */
  286.         InvalRect(&GrowRect);                        /* Flag us to update it */
  287.  
  288.         SetRect(&GrowRect, OldRect.right - 15, 0, OldRect.right + 15, OldRect.bottom + 15);/* Position for vert scrollbar area */
  289.         EraseRect(&GrowRect);                        /* Erase old area */
  290.         InvalRect(&GrowRect);                        /* Flag us to update it */
  291.  
  292.         DrawGrowIcon(whichWindow);                    /* Draw the grow Icon again */
  293.         }                                        /* End of IF */
  294.     }                                            /* End of IF */
  295. }
  296.  
  297.  
  298.  
  299. /* Routine: DoDrag */
  300. /* Purpose: Drag a window around */
  301.  
  302. static void DoDrag(WindowPtr whichWindow)
  303. {
  304. Rect    OldRect;                            /* Window rect before the drag */
  305. Rect    tempRect;                            /* temporary rect */
  306. long    theRefCon;                            /* Refcon with layer masked off */
  307.  
  308.     if ((!Doing_MovableModal) || (Doing_MovableModal && (whichWindow == FrontWindow()))) {    /* See if OK to drag */
  309.         OldRect = whichWindow->portRect;    /* Save the rect before resizing */
  310.  
  311.         tempRect = qd.screenBits.bounds;    /* Get screen area,  l,t,r,b, drag area */
  312.         SetRect(&tempRect,tempRect.left+4,tempRect.top+4,tempRect.right-4,tempRect.bottom - 4);
  313.         DragWindow(whichWindow, myEvent.where, &tempRect);    /* Drag the window */
  314.  
  315.         theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  316.         switch (theRefCon) {                /* Do the appropiate window */
  317.             case Res_W_ARTAbrot:
  318.                 Moved_ARTAbrot(whichWindow);    /* Moved this window */
  319.                 break;
  320.             case Res_MD_About_ARTAbrot:
  321.                 Moved_About_ARTAbrot(whichWindow);    /* Moved this modeless dialog */
  322.                 break;
  323.             case Res_MD_Enter_Coordinat:
  324.                 Moved_Enter_Coordinat(whichWindow);    /* Moved this modeless dialog */
  325.                 break;
  326.             default:                        /* allow other buttons, trap for debug */
  327.                 break;    
  328.         }    
  329.     }    
  330. }
  331.  
  332.  
  333.  
  334. /* Routine: DoGoAway */
  335. /* Purpose: Close a window */
  336.  
  337. static void DoGoAway(WindowPtr whichWindow)
  338. {
  339. long    theRefCon;                                    /* Refcon with layer masked off */
  340.  
  341.     if (!Doing_MovableModal) {                            /* Select proper window */
  342.         if (TrackGoAway(whichWindow,myEvent.where)) {    /* See if mouse released in GoAway box */
  343.             theRefCon = GetWRefCon(whichWindow);        /* Get the refcon */
  344.             switch (theRefCon) {                            /* Do the appropiate window */
  345.                 case Res_W_ARTAbrot:
  346.                     Close_ARTAbrot(whichWindow);        /* Close this window */
  347.                     break;
  348.                 case Res_MD_About_ARTAbrot:
  349.                     Close_About_ARTAbrot(whichWindow);/* Close this modeless dialog */
  350.                     break;
  351.                 case Res_MD_Enter_Coordinat:
  352.                     Close_Enter_Coordinat(whichWindow);/* Close this modeless dialog */
  353.                     break;
  354.                 default:                            /* allow other buttons, trap for debug */
  355.                     break;    
  356.             }    
  357.         }    
  358.     }    
  359. }
  360.  
  361.  
  362.  
  363. /* Routine: DoInContent */
  364. /* Purpose: Pressed in the content area */
  365.  
  366. static void DoInContent(WindowPtr whichWindow,EventRecord *myEvent)
  367. {
  368. long    theRefCon;                            /* Refcon with layer masked off */
  369.  
  370.     if (!Doing_MovableModal) {                /* Select proper window */
  371.         if (whichWindow != FrontWindow()) {    /* See if already selected or not, in front if selected */
  372.             SelectWindow(whichWindow);        /* Select this window to make it active */
  373.         }
  374.         else {
  375.             SetPort(whichWindow);            /* Get ready to draw in this window */
  376.             theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  377.             switch (theRefCon) {            /* Do the appropiate window */
  378.                 case Res_W_ARTAbrot:
  379.                     Do_ARTAbrot(myEvent);    /* Handle this window */
  380.                     break;
  381.                 default:                    /* allow other buttons, trap for debug */
  382.                     break;
  383.             }
  384.         }
  385.     }
  386. }
  387.  
  388.  
  389.  
  390. /* Routine: DoUpdate */
  391. /* Purpose: Got an update event */
  392.  
  393. static void DoUpdate()
  394. {
  395. WindowPtr    whichWindow;                    /* See which window for event */
  396. long    theRefCon;                            /* Refcon with layer masked off */
  397.  
  398.     whichWindow = (WindowPtr)myEvent.message;    /* Get the window the update is for */
  399.  
  400.     BeginUpdate(whichWindow);                /* Set the clipping to the update area */
  401.     theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  402.     switch (theRefCon) {                    /* Do the appropiate window */
  403.         case Res_W_ARTAbrot:
  404.             Update_ARTAbrot(whichWindow);    /* Update this window */
  405.             break;
  406.         default:                            /* allow other buttons, trap for debug */
  407.             break;
  408.     }
  409.     EndUpdate(whichWindow);                    /* Return to normal clipping area */
  410. }
  411.  
  412.  
  413.  
  414. /* Routine: DoActivate */
  415. /* Purpose: Got an activate or deactivate event */
  416.  
  417. void DoActivate()
  418. {
  419. WindowPtr    whichWindow;                /* See which window for event */
  420. Boolean    Do_An_Activate;                    /* Flag to pass */
  421. long    theRefCon;                        /* Refcon with layer masked off */
  422.  
  423.     whichWindow = (WindowPtr)myEvent.message;    /* Get the window the update is for */
  424.  
  425.     Do_An_Activate =  ((myEvent.modifiers & 0x0001) != 0);    /* Make sure it is Activate and not DeActivate */
  426.     theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  427.     switch (theRefCon) {                /* Do the appropiate window */
  428.         case Res_W_ARTAbrot:
  429.             Activate_ARTAbrot(whichWindow,Do_An_Activate);    /* Activate or deactivate this window */
  430.             break;
  431.         default:                        /* allow other buttons, trap for debug */
  432.             break;
  433.     }
  434. }
  435.  
  436.  
  437.  
  438. void main()
  439. {
  440. char tmp_string[256];
  441.  
  442.     MoreMasters();                        /* This reserves space for more handles */
  443.     MaxApplZone();                        /* Give us room for memory allocation */
  444.     InitGraf((Ptr) &qd.thePort);        /* Quickdraw Init */
  445.     InitFonts();                        /* Font manager init */
  446.     InitWindows();                        /* Window manager init */
  447.     InitMenus();                        /* Menu manager init */
  448.     TEInit();                            /* Text edit init */
  449.     InitDialogs(nil);                    /* Dialog manager */
  450.  
  451.     FlushEvents(everyEvent , 0);        /* Clear out all events */
  452.     InitCursor();                        /* Make an arrow cursor */
  453.  
  454.     doneFlag = FALSE;                    /* Do not exit program yet */
  455.  
  456.     Init_My_Menus();                    /* Initialize menu bar */
  457.  
  458.     theInput = nil;                        /* Init to no text edit selection active */
  459.  
  460.     SleepValue = 40;                    /* Set sleep value */
  461.     WNE = IsWNEIsImplemented();            /* See if WaitNextEvent is available */
  462.  
  463.     /* We need certain minimum conditions.  We'll check here. */
  464.     if (!HasGestalt) {
  465.         sprintf(tmp_string, "Sorry, Gestalt required for this program.");
  466.         AB_Alert(tmp_string);
  467.         doneFlag = TRUE;                /* Exit program. */
  468.     }
  469.     else {
  470.         if (!HasColorQD) {
  471.             sprintf(tmp_string, "Sorry, Color Quickdraw required for this program.");
  472.             AB_Alert(tmp_string);
  473.             doneFlag = TRUE;            /* Exit program. */
  474.         }
  475.     }
  476.  
  477.     UserEventList = nil;                /* No user events yet */
  478.  
  479.     cursorRgn = NewRgn();                /* Cursor region for WaitNextEvent */
  480.  
  481.     Init_ARTAbrot();                    /* Initialize the window routines */
  482.     Init_About_ARTAbrot();                /* Initialize the modeless dialog routines */
  483.     I_A_Alert();                        /* Initialize the alert globals */
  484.     Init_Enter_Coordinat();                /* Initialize the modeless dialog routines */
  485.     Doing_MovableModal = false;            /* Not currently doing a movable modal */
  486.  
  487.  
  488.     do {
  489.         Handle_User_Event();            /* Check for user events */
  490.         if (theInput != NIL) {            /* See if a TE is active */
  491.             TEIdle(theInput);            /* Blink the cursor if everything is ok */
  492.         }
  493.         if (WNE) {                        /* See if do the MultiFinder way */
  494.             DoIt = WaitNextEvent(everyEvent, &myEvent, SleepValue, cursorRgn);/* Wait for an event */
  495.         }
  496.         else {
  497.             SystemTask();                /* For support of desk accessories */
  498.             DoIt = GetNextEvent(everyEvent, &myEvent);/* See if an event is ready */
  499.         }
  500.  
  501.         if (DoIt) {                        /* If event then... */
  502.             Is_A_Dialog = IsDialogEvent(&myEvent);    /* See if a modeless dialog event */
  503.             if (Is_A_Dialog == TRUE) {                /* Handle a dialog event */
  504.                 if (myEvent.what == updateEvt) {    /* Handle the update of a Modeless Dialog */
  505.                     whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
  506.                     BeginUpdate(whichWindow);        /* Set update clipping area */
  507.                     Update_About_ARTAbrot(whichWindow);    /* Update the modeless dialog */
  508.                     Update_Enter_Coordinat(whichWindow);/* Update the modeless dialog */
  509.                     EndUpdate(whichWindow);            /* Return to normal clipping area */
  510.                 }
  511.                 else {
  512.                     DoTheModelessEvent = TRUE;        /* Go ahead and do it so far */
  513.  
  514.                     if (myEvent.what == keyDown) {     /* Check the key down, for a command key event */
  515.                         CmdDown = ((myEvent.modifiers / cmdKey) & 1);/* Get the command key state */
  516.                         charCode = myEvent.message & charCodeMask;/* Get the character */
  517.                         ch = (char)charCode;        /* Change it to ASCII */
  518.  
  519.                         if ((charCode == 13) || (charCode == 0x03))/* CR or Enter */
  520.                             DoTheModelessEvent = TRUE;/* Handle the default selection */
  521.  
  522.                         if (CmdDown != 0) {            /* Handle if the command key was down */
  523.                             mResult = MenuKey(ch);    /* See if a menu selection */
  524.                             theMenu = HiWord(mResult);    /* Get the menu list number */
  525.                             theItem = LoWord(mResult);    /* Get the menu item number */
  526.                             if (theMenu != 0)          /* See if a list was selected */
  527.                                 Handle_My_Menu(theMenu, theItem); /* Do the menu selection */
  528.  
  529.                             whichWindow = FrontWindow(); /* Get the front window */
  530.                             if ((ch == 'x') || (ch == 'X'))    /* Handle a CUT */
  531.                                 DlgCut(whichWindow);/* Do the dialog cut */
  532.                             if ((ch == 'c') || (ch == 'C'))    /* Handle a COPY */
  533.                                 DlgCopy(whichWindow);/* Do the dialog copy */
  534.                             if ((ch == 'v') || (ch == 'V'))    /* Handle a PASTE */
  535.                                 DlgPaste(whichWindow);    /* Do the dialog paste */
  536.  
  537.                             DoTheModelessEvent = FALSE;/* We handled the command key */
  538.                         }
  539.                     }
  540.  
  541.                     if (DoTheModelessEvent == TRUE) {     /* Do we handle it? */
  542.                         if ((DialogSelect(&myEvent, &whichWindow, &itemHit)) || (myEvent.what == mouseDown) || (myEvent.what == keyDown)) { /* Ck if do it */
  543.                             Do_About_ARTAbrot(&myEvent,whichWindow,itemHit);    /* Handle the Modeless Dialog */
  544.                             Do_Enter_Coordinat(&myEvent,whichWindow,itemHit);    /* Handle the Modeless Dialog */
  545.                         }
  546.                     }
  547.                 }
  548.             }
  549.             else {
  550.                 switch (myEvent.what) {        /* Decide type of event */
  551.                     case mouseDown :        /* Mouse button pressed */
  552.                         code = FindWindow(myEvent.where, &whichWindow);/* Get which window the event happened in */
  553.  
  554.                         switch (code) {        /* Decide type of event again */
  555.                             case inMenuBar:    /* In the menubar */
  556.                                 mResult = MenuSelect(myEvent.where);    /* Do menu selection */
  557.                                 theMenu = HiWord(mResult);    /* Get the menu list number */
  558.                                 theItem = LoWord(mResult);    /* Get the menu list item number */
  559.                                 Handle_My_Menu( theMenu, theItem);    /* Handle the menu */
  560.                                 break;
  561.  
  562.                             case inDrag:    /* In window drag area */
  563.                                 DoDrag(whichWindow);    /* Go drag the window */
  564.                                 break;
  565.  
  566.                             case inGrow:    /* In window grow area */
  567.                                 DoGrow(whichWindow);    /* Handle the growing */
  568.                                 break;
  569.  
  570.                             case inGoAway:    /* In window goaway area */
  571.                                 DoGoAway(whichWindow);    /* Handle the goaway button */
  572.                                 break;
  573.  
  574.                             case inContent:    /* In window  contents */
  575.                                 DoInContent(whichWindow,&myEvent);    /* Handle the hit inside a window */
  576.                                 break;
  577.  
  578.                             case inSysWindow:    /* See if a DA selectio */
  579.                                 SystemClick(&myEvent, whichWindow);    /* Let other programs in */
  580.                                 break;
  581.  
  582.                             default:        /* Handle others */
  583.                                 break;
  584.                         }
  585.                         break;                /* End of MouseDown */
  586.  
  587.                     case keyDown:            /* Handle key inputs */
  588.                     case autoKey:            /* and auto repeats */
  589.                         DoKeyEvent();        /* Get the key and handle it */
  590.                         break;
  591.  
  592.                     case updateEvt:            /* Update event for a window */
  593.                         DoUpdate();            /* Handle the update */
  594.                         break;
  595.  
  596.                     case diskEvt:            /* Disk inserted event */
  597.                         DoDiskEvent();        /* Handle a disk event */
  598.                         break;
  599.  
  600.                     case activateEvt:        /* Window activated event */
  601.                         DoActivate();        /* Handle the activation */
  602.                         break;
  603.  
  604.                     case osEvt:                /* OS event */
  605.                         DoOSEvent(&myEvent);    /* Handle the activation */
  606.                         break;                    /* End of osEvt */
  607.  
  608.                     default:                /* Used for debugging, to see what other events are coming in */
  609.                         break;
  610.                 }
  611.             }
  612.         }
  613.         else {
  614.             whichWindow = FrontWindow();    /* Get the current front window */
  615.             if (whichWindow != NIL) {        /* See if we have a window */
  616.                 thePeeked = (WindowPeek)whichWindow;    /* Peek inside, look for dialog */
  617.                 if (thePeeked->windowKind == dialogKind) {    /* DialogSelect will crash if no dialogs */
  618.                     if (DialogSelect(&myEvent, &whichWindow, &itemHit)) { /* Blink cursor in modeless TEs */
  619.                     }
  620.                 }
  621.             }
  622.         }
  623.     }
  624.     while (doneFlag == FALSE);                /* End of the event loop */
  625. }                                            /* end of main */
  626.